<?

class Config extends db {
	
	function isValidSetting($setting) {
		$settings = explode(',', VALID_SETTINGS);
		return in_array($setting, $settings);
	}
	
	function getSetting($setting) {
		$q = "select value from Config where name = '{$setting}'";
		$r = @mysql_query($q);
		if (!$r) {
			return Error::MySQL();
		}
		$row = @mysql_fetch_assoc($r);	
		return $row['value'];
	}
	
	function update($setting, $value) {
		if (!Config::isValidSetting($setting)) {
			return Error::create("Unrecognized setting: {$setting}");
		}
		$q = "delete from Config where name = '{$setting}'";
		$r = @mysql_query($q);
		if (!$r) {
			return Error::MySQL();
		}
		
		$q = "insert into Config (name, value) values ('{$setting}', '" . db::sanitize_to_db($value) . "')";
		$r = @mysql_query($q);
		if (!$r) {
			return Error::MySQL();
		}
		
		return true;
	}
	
	
	
}

?>